package model

import (
	"database/sql/driver"
	"encoding/json"
	"tdy-backend/app/core/model"
)

type Material struct {
	model.BaseModel
	MemberId     uint          `gorm:"column:member_id;type:bigint(20);not null;comment:会员id"`
	Kind         int           `gorm:"column:kind;type:tinyint(4);not null;comment:类型 1普清 2高清"`
	Title        string        `gorm:"column:title;type:varchar(100);not null;comment:标题"`
	Path         string        `gorm:"column:path;type:varchar(200);not null;comment:路径"`
	Panoramic    string        `gorm:"column:panoramic;type:varchar(200);not null;comment:全景图片"`
	Status       uint          `gorm:"column:status;type:tinyint(4);not null;comment:状态 1待转码 2转码中 3转码完成 4转码失败"`
	Size         int64         `gorm:"column:size;type:int(11);not null;comment:全景大小"`
	Lat          float64       `gorm:"column:lat;type:decimal(10,6);default:null;comment:纬度"`
	Lng          float64       `gorm:"column:lng;type:decimal(10,6);default:null;comment:经度"`
	Alt          int           `gorm:"column:alt;type:int(11);default:null;comment:高度"`
	Info         *MaterialInfo `gorm:"column:info;type:json;default:null;comment:全景信息"`
	ThumbPreview string        `gorm:"-"`
	PathPreview  string        `gorm:"-"`
}

type MaterialInfo struct {
	TileSize   int
	Levels     int
	Resolution string
}

func (o MaterialInfo) Value() (driver.Value, error) {

	return json.Marshal(o)
}

func (o *MaterialInfo) Scan(input interface{}) error {
	if input == nil {
		return nil
	}
	return json.Unmarshal(input.([]byte), o)
}
